import { defineStore } from 'pinia'
import { addEvaluation, updateEvaluation, deleteEvaluation, getUserEvaluations, getActivityEvaluations } from '@/api/evaluation'

export const useEvaluationStore = defineStore('evaluation', {
  state: () => ({
    evaluations: [],
    total: 0,
    loading: false
  }),
  
  actions: {
    // 获取用户评价列表
    async getUserEvaluations(params) {
      this.loading = true
      try {
        const response = await getUserEvaluations(params)
        const { data } = response
        this.evaluations = data.records || []
        this.total = data.total || 0
        this.loading = false
        return Promise.resolve(data)
      } catch (error) {
        this.loading = false
        return Promise.reject(error)
      }
    },
    
    // 获取活动评价列表
    async getActivityEvaluations(params) {
      this.loading = true
      try {
        const response = await getActivityEvaluations(params)
        const { data } = response
        this.evaluations = data.records || []
        this.total = data.total || 0
        this.loading = false
        return Promise.resolve(data)
      } catch (error) {
        this.loading = false
        return Promise.reject(error)
      }
    },
    
    // 添加评价
    async addEvaluation(evaluationData) {
      try {
        const response = await addEvaluation(evaluationData)
        return Promise.resolve(response)
      } catch (error) {
        return Promise.reject(error)
      }
    },
    
    // 更新评价
    async updateEvaluation(evaluationData) {
      try {
        const response = await updateEvaluation(evaluationData)
        return Promise.resolve(response)
      } catch (error) {
        return Promise.reject(error)
      }
    },
    
    // 删除评价
    async deleteEvaluation(id) {
      try {
        const response = await deleteEvaluation(id)
        return Promise.resolve(response)
      } catch (error) {
        return Promise.reject(error)
      }
    }
  }
}) 